using System;
using System.Collections.Generic;
using System.Linq;

public class GGResolveConflict
{
	public static T ResolveConflictTakeMin<T>(T remote, T local) where T : IComparable
	{
		if (remote.CompareTo(local) < 0)
		{
			return remote;
		}
		return local;
	}

	public static T ResolveConflictTakeMax<T>(T remote, T local) where T : IComparable
	{
		if (remote.CompareTo(local) > 0)
		{
			return remote;
		}
		return local;
	}

	public static T ResolveConflictTakeRemoteClassIfNotNull<T>(T remote, T local) where T : class
	{
		if (remote != null)
		{
			return remote;
		}
		return local;
	}

	public static T ResolveConflictTakeLocalClassIfNotNull<T>(T remote, T local) where T : class
	{
		if (local != null)
		{
			return local;
		}
		return remote;
	}

	public static List<T> ResolveConflictTakeRemoteListIfNotEmpty<T>(List<T> remote, List<T> local) where T : class
	{
		if (remote != null && remote.Count > 0)
		{
			return remote;
		}
		return local;
	}

	public static List<T> ResolveConflictTakeLocalListIfNotEmpty<T>(List<T> remote, List<T> local) where T : class
	{
		if (local != null && local.Count > 0)
		{
			return local;
		}
		return remote;
	}

	public static List<T> ResolveConflictMerge<T>(List<T> remote, List<T> local, IMergeInterface<T> merger) where T : class
	{
		if (remote == null || remote.Count == 0)
		{
			GGDebug.DebugLog("remote null");
			return local;
		}
		if (local == null || local.Count == 0)
		{
			GGDebug.DebugLog("local null");
			return remote;
		}
		List<T> list = remote.Concat(local).ToList();
		int num = list.Count - 1;
		for (int i = 0; i < num; i++)
		{
			int num2 = i + 1;
			while (num2 <= num)
			{
				if (merger.MyEquals(list[i], list[num2]))
				{
					list[i] = merger.MyResolver(list[i], list[num2]);
					list[num2] = list[num];
					list.RemoveAt(num);
					num--;
				}
				else
				{
					num2++;
				}
			}
		}
		return list;
	}
}
